1、新建config.gradle
在android studio的根项目中新建config.gradle文件(和settings.gradble同目录)
开始写想要的信息
ext {
android = [
compileSdkVersion : 26,
buildToolsVersion : '26.0.2',
applicationId : 'com.laisontech.rxjavedemo',
minSdkVersion : 17,
targetSdkVersion : 26,
versionCode : 1,
versionName : 'v 1.1.0',
defaultPublishConfig: 'release',
publishNonDefault : true
]
dependencies = [
"appcompat-v7" : 'com.android.support:appcompat-v7:26.1.0',
"support-design" : 'com.android.support:design:+',
"junit" : 'junit:junit:4.12',
"gson" : 'com.google.code.gson:gson:2.8.0',
"rxandroid" : 'io.reactivex:rxandroid:1.2.1',
"rxjava" : 'io.reactivex:rxjava:1.2.4',
"constraint-layout": 'com.android.support.constraint:constraint-layout:1.0.2',
"retrofit" : 'com.squareup.retrofit2:retrofit:2.2.0',
"converter-gson" : 'com.squareup.retrofit2:converter-gson:2.2.0',
"adapter-rxjava" : 'com.squareup.retrofit2:adapter-rxjava:2.1.0',
"butterknife" : 'com.jakewharton:butterknife:8.5.1',
"eventbus" : 'org.greenrobot:eventbus:3.0.0'
]
}
2、在moule.gradle中写入配置信息
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
defaultConfig {
applicationId rootProject.ext.android["applicationId"]
minSdkVersion rootProject.ext.android["minSdkVersion"]
targetSdkVersion rootProject.ext.android["targetSdkVersion"]
versionCode rootProject.ext.android["versionCode"]
versionName rootProject.ext.android["versionName"]
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile rootProject.ext.dependencies["constraint-layout"]
compile rootProject.ext.dependencies["junit"]
compile rootProject.ext.dependencies["appcompat-v7"]
compile rootProject.ext.dependencies["rxandroid"]
compile rootProject.ext.dependencies["rxjava"]
compile rootProject.ext.dependencies["gson"]
compile rootProject.ext.dependencies["retrofit"]
compile rootProject.ext.dependencies["converter-gson"]
compile rootProject.ext.dependencies["adapter-rxjava"]
compile rootProject.ext.dependencies["eventbus"]
compile rootProject.ext.dependencies["butterknife"]
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
3、在项目的build.gradle中添加
apply from: "config.gradle"
最后重构这个项目即可。